//
// Delaunay Triangulation
//
// Homework of CG lesson (Fall 2009) in Tsinghua University.
// All rights reserved.
//

// temp include, delete later if necessary
#include "stdafx.h"

#include "vector2d.h"

// C++ headers
#include <cmath>

Vector2d::Vector2d(void)
    :x(0), y(0)
{
}

Vector2d::Vector2d(double tx, double ty)
    :x(tx), y(ty)
{
}

Vector2d::Vector2d(const Vector2d& vect)
{
    x = vect.x;
    y = vect.y;
}

double Vector2d::norm(void) const
{
    return sqrt(x * x + y * y);
}

double Vector2d::squareNorm(void) const
{
    return x * x + y * y;
}

bool Vector2d::normalize(void)
{
    double len = this->norm();
    if (len == 0.0)
    {
        return false;
    }
    else
    {
        x /= len;
        y /= len;

        return true;
    }
}

double Vector2d::dot(const Vector2d& vect)
{
    return (x * vect.x + y * vect.y);
}

Vector2d Vector2d::operator*(double c) const
{
    return Vector2d(c * x, c * y);
}

Vector2d& Vector2d::operator*=(double c)
{
    x *= c;
    y *= c;

    return *this;
}

Vector2d Vector2d::operator+(const Vector2d& vect) const
{
    return Vector2d(x + vect.x, y + vect.y);
}

Vector2d& Vector2d::operator+=(const Vector2d& vect)
{
    x += vect.x;
    y += vect.y;

    return *this;
}

Vector2d Vector2d::operator-(const Vector2d& vect) const
{
    return Vector2d(x - vect.x, y - vect.y);
}

Vector2d& Vector2d::operator-=(const Vector2d& vect)
{
    x -= vect.x;
    y -= vect.y;

    return *this;
}
